Ext.define('TS.lib.Window',{
	extend:'Ext.window.Window',
	alias:'window',
	autoShow:true,
	autoDestroy:true,
	layout:'fit',
	frame:false,
	stateful:false,
	closeAction:'destroy',// DEFAULT
	border:false,
	listeners:{
		beforerender:{
			fn: function(comp,e){
				this.y = this.y < 0 ? 0 : this.y;
			}
		}
	},
	constructor:function(c){
		this.callParent(arguments);
		this.initConfig(c);
		this.on('move',this.onMove);//potrzebne
	},
	initComponent:function(c){
		this.callParent(arguments);//Calling the parent class constructor
		this.initConfig(c);//Initializing the component
		
		c && typeof c.onShow ==='function' && this.on('show',c.onShow);
		
	},
	
	onMove:function(component,x,y,eOpts){
		if (this.y < 0) this.setPosition(this.x,0);
		if (this.getHeight() > window.innerHeight){
			this.setHeight(window.innerHeight - 100)
		} else {
			if (this.y > window.innerHeight - this.getHeight() ) 
				this.setPosition(this.x,window.innerHeight - this.getHeight());
		}
		if (this.getWidth() > window.innerWidth) 
			this.setWidth(window.innerWidth -10);
		if (this.x < 0) 
			this.setPosition(0,this.y);
		if (this.x > window.innerWidth - this.getWidth()) 
			this.setPosition(window.innerWidth - this.getWidth(),this.y);
	}
});
